from typing import List


class Solution:
    def addToArrayForm(self, num: List[int], k: int) -> List[int]:
        ans, carry = [], 0
        i = 0
        while i < len(num) or k > 0:
            n1 = num[-i - 1] if len(num) - 1 - i >= 0 else 0
            n2 = k % 10
            sumVal = n1 + n2 + carry
            ans.append(sumVal % 10)
            carry = sumVal // 10
            k = k // 10
            i += 1
        if carry:
            ans.append(carry)
        return ans[::-1]